//
//  VCOfRegisterThird.m
//  XYFMApp
//
//  Created by 岁变 on 16/8/29.
//  Copyright © 2016年 岁变. All rights reserved.
//
#import "XYMacro.h"

@interface VCOfRegisterThird ()
@property (nonatomic, strong) UIButton *setUpButton;
@property (nonatomic, strong) UIImageView *headerImageView;
@property (nonatomic, strong) UILabel *nameLabel;

@property (nonatomic, strong) AnchorInformationCustomView *sexView;
@property (nonatomic, strong) AnchorInformationCustomView *ageVeiw;
@property (nonatomic, strong) AnchorInformationCustomView *brithVeiw;
@property (nonatomic, strong) AnchorInformationCustomView *constellationView;
@property (nonatomic, strong)  ModelOfMineTwo *model;

@end

@implementation VCOfRegisterThird

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    [self configNavigationController];
    [self configViewController];
    
    if ([user objectForKey:@"password"]) {
        [self sendLoadinMessage];
    }
}

- (void)sendLoadinMessage {
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *password = [user objectForKey:@"password"];
    NSString *phoneNumber = [user objectForKey:@"phoneNumber"];
    
    NSString *str1 = @"json=%7B%22password%22%3A%22";
    NSString *str2 = @"%22%2C%22username%22%3A%22";
    NSString *str3 = @"%22%7D";
    NSString *body = [[[[str1 stringByAppendingString:password] stringByAppendingString:str2] stringByAppendingString:phoneNumber] stringByAppendingString:str3];
    
    [XYNetWorkParser POST:@"http://www.aiyinsitanfm.com/mobile/user/signin.jhtml" andBody:body andBodyStyle:XYBodyString andHeader:URLHEADER andResponse:XYJSON andSuccessBlock:^(id result) {
        _model = [ModelOfMineTwo modelWithDictionary:result];
        _nameLabel.text = _model.user.nickname;
        _ageVeiw.contentLabel.text = [NSString stringWithFormat:@"%ld", _model.user.age];
        _brithVeiw.contentLabel.text = _model.user.birthday;
        _constellationView.contentLabel.text = _model.user.constellation;
        if ([_model.user.gender isEqualToString:@"1"]) {
            _sexView.contentLabel.text = @"男";
        } else {
            _sexView.contentLabel.text = @"女";
        }
    } andFailureBlock:^(NSError *error) {}];
    
}



- (void)configNavigationController {
    self.title = @"我的主页";
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
    UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    redView.backgroundColor = [UIColor redColor];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:redView];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    NSArray *arr = @[self];
    self.navigationController.viewControllers = arr;
    
}

- (void)configViewController {
    
    self.view.backgroundColor = [UIColor colorWithRed:0.91 green:0.93 blue:0.94 alpha:1.00];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"touxiang_bg"]];
    imageView.userInteractionEnabled = YES;
    [self.view addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).with.offset(0);
        make.left.equalTo(self.view.mas_left).with.offset(0);
        make.right.equalTo(self.view.mas_right).with.offset(0);
        make.height.mas_offset(200);
    }];
    
    
    _headerImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bigAvatar"]];
    _headerImageView.clipsToBounds = YES;
    [imageView addSubview:_headerImageView];
    [_headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageView.mas_top).with.offset(30);
        make.centerX.equalTo(imageView.mas_centerX);
        make.width.mas_offset(80);
        make.height.mas_offset(80);
    }];
    _headerImageView.layer.cornerRadius = 40;
    _headerImageView.layer.borderWidth = 3;
    _headerImageView.layer.borderColor = [UIColor redColor].CGColor;
    
    
    _setUpButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_setUpButton setImage:[UIImage imageNamed:@"my_setting"] forState:UIControlStateNormal];
    [_setUpButton addTarget:self action:@selector(setUp:) forControlEvents:UIControlEventTouchUpInside];
    [imageView addSubview:_setUpButton];
    [_setUpButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageView.mas_top).with.offset(20);
        make.left.equalTo(imageView.mas_left).with.offset(20);
        make.width.mas_offset(40);
        make.height.mas_offset(40);
    }];
    _setUpButton.layer.cornerRadius = 20;
    
    _nameLabel = [[UILabel alloc] init];
    _nameLabel.textColor = [UIColor whiteColor];
    _nameLabel.font = [UIFont systemFontOfSize:13];
    _nameLabel.text = _name;
    _nameLabel.textAlignment = NSTextAlignmentCenter;
    [imageView addSubview:_nameLabel];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_headerImageView.mas_bottom).with.offset(10);
        make.centerX.equalTo(imageView.mas_centerX);
        make.width.mas_offset(200);
        make.height.mas_offset(20);
    }];
    
    UILabel *labelOne = [[UILabel alloc] init];
    labelOne.backgroundColor = BACKGROUNDCOLOR;
    labelOne.textAlignment = NSTextAlignmentCenter;
    labelOne.textColor = [UIColor whiteColor];
    labelOne.text = @"资料";
    [self.view addSubview:labelOne];
    [labelOne mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).with.offset(0);
        make.right.equalTo(self.view.mas_right).with.offset(0);
        make.top.equalTo(imageView.mas_bottom).with.offset(0);
        make.height.mas_offset(50);
    }];
   
    _sexView = [[AnchorInformationCustomView alloc] initWithFrame:CGRectMake(0, 290, SCREEN_WIDTH, 50) title:@"性别"];
    _sexView.contentLabel.text = _gender;
    _sexView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_sexView];
    
    _ageVeiw = [[AnchorInformationCustomView alloc] initWithFrame:CGRectMake(0, 340, SCREEN_WIDTH, 50) title:@"年龄"];
    _ageVeiw.contentLabel.text = _age;
    _ageVeiw.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_ageVeiw];
    
    _brithVeiw = [[AnchorInformationCustomView alloc] initWithFrame:CGRectMake(0, 390, SCREEN_WIDTH, 50) title:@"出生年月"];
    _brithVeiw.contentLabel.text = _brithday;
    _brithVeiw.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_brithVeiw];
    
    _constellationView = [[AnchorInformationCustomView alloc] initWithFrame:CGRectMake(0, 440, SCREEN_WIDTH, 50) title:@"星座"];
    _constellationView.contentLabel.text = _constellation;
    _constellationView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_constellationView];
}


- (void)setUp:(UIButton *)button {
    VCOfSetUp *nextVC = [[VCOfSetUp alloc] init];
    [self.navigationController pushViewController:nextVC animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
